package com.example.demo.controller;

import com.example.demo.model.Blog;
import com.example.demo.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class IndexController {
    @Autowired
    private BlogService blogService;

    @RequestMapping("/index")
    public List<Blog> getAllBlog() {
        List<Blog> blogs = blogService.getAllBlog();
        for (Blog blog : blogs) {
            if (blog.getContent().length() > 80) {
                blog.setContent(blog.getContent().substring(0,80) + " ...");
            }
        }
        return blogs;
    }
}
